{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b0f38528",
   "metadata": {},
   "source": [
    "* 本周内容\n",
    "> 人脸识别概念和基础 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7da232d",
   "metadata": {},
   "source": [
    "# 人脸识别（Face++ & 百度AI）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c5050b36",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'request_id': '1678938361,dbef4bb0-e846-4c3f-8205-b7d68c541541',\n",
       " 'time_used': 153,\n",
       " 'faces': [{'face_token': 'ad1910ec4822b4c6de4b39c6baae718d',\n",
       "   'face_rectangle': {'top': 105, 'left': 67, 'width': 53, 'height': 53},\n",
       "   'attributes': {'gender': {'value': 'Male'},\n",
       "    'age': {'value': 24},\n",
       "    'smile': {'value': 99.949, 'threshold': 50.0},\n",
       "    'beauty': {'male_score': 78.854, 'female_score': 86.257}}}],\n",
       " 'image_id': '79r7QlMJNd/IEAKtpNhz9A==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('薛之谦.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"image_base64\":img,\n",
    "    \"api_key\":\"psRtU34vw2g2zgyham0f07f_TTYvxRDq\",\n",
    "    \"api_secret\":\"f-dc0uq80x06l73mpzKvwG3uVeG0iWgE\",\n",
    "    \"return_attributes\":\"gender,age,smiling,beauty\"\n",
    "}\n",
    "\n",
    "request_url = request_url \n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print (response.status_code)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "812eac1f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
